Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Allow subscriber to be collected if MessagingCenter is the only reference to it #617

Merged
merged 9 commits into from
Jan 3, 2017

Conversation

hartez
Copy link
Contributor

@hartez hartez commented Dec 6, 2016

Description of Change

If the target of a MessagingCenter callback is the subscriber, keep a weak reference to the subscriber to allow it to be garbage collected.

Also refactored MessagingCenter slightly because I got tired of miscounting the angle brackets.

Bugs Fixed

API Changes

None

Behavioral Changes

None

PR Checklist

  • Has tests (if omitted, state reason in description)
  • Rebased on top of master at time of PR
  • Changes adhere to coding standard
  • Consolidate commits as makes sense

Copy link
Member

@StephaneDelcroix StephaneDelcroix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good. the UITest is not required, but a UnitTest is. Could you please add one?
Grep the code for create() to see how we trick the GC to collect objects with Mono

@hartez hartez changed the title Make MessagingCenter callback a WeakReference to allow subscriber collection Allow subscriber to be collected if MessagingCenter is the only reference to it Dec 15, 2016
@hartez
Copy link
Contributor Author

hartez commented Dec 16, 2016

@StephaneDelcroix This one is ready for another look.

@rmarinho rmarinho merged commit 58909e2 into master Jan 3, 2017
rookiejava pushed a commit to rookiejava/Xamarin.Forms that referenced this pull request Jan 9, 2017
…ence to it (xamarin#617)

* Repro

* Make messaging center callbacks weak references

* Preserve attribute

* Fix test method name

* Watch for collection of actual delegate target instead of wrapper delegate

* Preserve the original platform instance when changing main page

* Better tests for lambda situations

* Update tests, make callback target a weakreference if it's the subscriber

* Ensure old Platform MessagingCenter subs are gone before creating new Platform
@hartez hartez mentioned this pull request Jan 27, 2017
4 tasks
rmarinho pushed a commit that referenced this pull request Feb 2, 2017
* Add pressed and released events to Button

* Update ButtonRenderer.cs

* Apply safely casting to android button renderer

* Use safety casting for Android buttin renderer

* [Windows] Fix modal pages being laid out below soft buttons (#395)

* Add sample HanselForms and TwitterDemo to ControlGallery (#651)

* [Controls] Add Hanselforms sample

* Remove extra twitter sample

* [Controls]Add TwitterDemo sample

* [Controls] Fix build

* Slider should show user-set value on initial load (#378)

* [UWP] Use toolbar foreground color on primary items (#640)

* Avoid duplicating code in OmPlatform (#591)

* [iOS] Entry should not pass a newline to the next responder (#397)

* UITextField should not return so that the next field does not get passed a newline

* Added code sample

* [XamlC] import members on x:Static and factories (#642)

* [Xaml] support short Properties for PropertyCondition (#645)

* Xamlc compile data triggers (#648)

* [Xaml] DataTrigger and PropertyCondition no longer use a ServiceProvider

* [XamlC] avoid generating ServiceProvider for unused ProvideValue

* fix tests

* Fix comment typo

* [UWP] Fix TextBox style for foreground focus color (#618)

* Adding image to use for CellsGalleryImageUrlCellList UI test

* Update ImageCellListPage to use an image we control;
Update CellsGalleryImageUrlCellList test to wait longer than 1s for images
to load if necessary

* fix nre when changing content in datepickerselected (#494)

* Make CellsGalleryImageUrlCellList test finish early if possible

* [iOS] Change keyboard type while keyboard is visible (#443)

* Change keyboard while changing text

* add sample code

* [Android] Fix NavigationPage dispose crash when it parents a MasterDetailPage (#577)

* fix navigation page dispose crash

* changes after review

* [XamlC] detect duplicate x:Name at compile time (#655)

* [XamlC] detect duplicate x:Name at compile time

* invoking methods with the right arguments produces better results

* Make UWP toolbar display rules consistent with other platforms (#638)

* Allow subscriber to be collected if MessagingCenter is the only reference to it (#617)

* Repro

* Make messaging center callbacks weak references

* Preserve attribute

* Fix test method name

* Watch for collection of actual delegate target instead of wrapper delegate

* Preserve the original platform instance when changing main page

* Better tests for lambda situations

* Update tests, make callback target a weakreference if it's the subscriber

* Ensure old Platform MessagingCenter subs are gone before creating new Platform

* [iOS] Prevent multiple ListView cells from being swiped simultaneously (#578)

* disable multiple cell swipe

* add sample code

* refactored

* convert to weakreference

* remove null setting

* change weakreference setting place

* remove if

* revert isopen changes

* add instructions

* [WinRT/UWP] Apply BackgroundColor to Stepper buttons (#581)

* [WinRT/UWP] Apply BackgroundColor to Stepper buttons

* Add explanatory text; use nameof

* Move explanatory text to a label

* Return group instead of internal class (#461)

* [iOS/Android] Move Map camera to correct region on layout change (#548)

* Move to region on layout change

* remove visibility check

* [iOS] Platform specifics for controlling Picker SelectedIndex change behavior (#540)

* picker selected index could change when picker view is dismissed

* use enum

* [iOS] Ignore intermittent failing test on XTC (#666)

* [UITest] Update to UITest 2.0.5 (#665)

* Rebase the current branch onto upstream latest
@hartez hartez deleted the fix-bugzilla45926 branch May 16, 2017 16:52
@samhouts samhouts added this to the 2.3.4 milestone Jun 27, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants